<template>
   <div class="retrieve-bottle-page">
    <div class="page-header">
      <h2>捞瓶子</h2>
      <p>从大海中捞起一个漂流瓶，看看别人分享了什么</p>
    </div>

    <div class="retrieve-content">
      <div class="fishing-animation" v-if="isFishing">
        <div class="fishing-rod">
          <div class="rod-line"></div>
          <div class="hook">🎣</div>
        </div>
        <div class="water-waves">
          <div class="wave"></div>
          <div class="wave"></div>
          <div class="wave"></div>
        </div>
        <p class="fishing-text">正在努力捞瓶子中...</p>
      </div>

      <div class="caught-bottle" v-else-if="caughtBottle">
        <div class="bottle-animation">
          <div class="bottle-icon">🍶</div>
          <div class="sparkles">
            <span class="sparkle">✨</span>
            <span class="sparkle">⭐</span>
            <span class="sparkle">💫</span>
          </div>
        </div>
        <h3>恭喜！你捞到了一个瓶子</h3>
        <div class="bottle-content-card">
          <div class="bottle-header">
            <img :src="caughtBottle.avatar" :alt="caughtBottle.username" class="caught-avatar" />
            <div class="caught-info">
              <h4>{{ caughtBottle.username }}</h4>
              <span class="caught-distance">{{ caughtBottle.distance }}km</span>
            </div>
          </div>
          <p class="caught-message">{{ caughtBottle.message }}</p>
          <div class="caught-tags">
            <span v-for="tag in caughtBottle.tags" :key="tag" class="caught-tag">{{ tag }}</span>
          </div>
          <div class="caught-meta">
            <span>{{ caughtBottle.timeAgo }}</span>
            <span>来自 {{ caughtBottle.location }}</span>
          </div>
        </div>
        <div class="retrieve-actions">
          <button class="action-btn reply-btn" @click="replyToBottle">回复</button>
          <button class="action-btn like-btn" @click="likeBottle">
            {{ caughtBottle.isLiked ? '取消赞' : '点赞' }} ❤️
          </button>
          <button class="action-btn" @click="resetFishing">继续捞瓶子</button>
        </div>
      </div>

      <div class="empty-state" v-else>
        <div class="empty-icon">🎣</div>
        <h3>开始捞瓶子吧</h3>
        <p>点击下方按钮，开始你的捞瓶子之旅</p>
        <button class="primary-btn" @click="startFishing">
          <span>开始捞瓶子</span>
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import avatarChenyundong from '@/assets/images/avatar_chenyundong.png'

// 响应式数据
const isFishing = ref(false)
const caughtBottle = ref(null)

// 模拟数据
const bottleData = {
  id: 1,
  username: '晨运动',
  avatar: avatarChenyundong,
  message: '今天跑了10公里，感觉超棒！谁要一起晨跑？',
  tags: ['#跑步', '#晨练'],
  likes: 12,
  isLiked: false,
  timeAgo: '2小时前',
  location: '中央公园',
  distance: '2.5'
}

// 开始捞瓶子
const startFishing = () => {
  isFishing.value = true
  caughtBottle.value = null

  // 模拟捞瓶子过程，2-4秒随机延迟
  const fishingTime = Math.random() * 2000 + 2000

  setTimeout(() => {
    isFishing.value = false
    caughtBottle.value = { ...bottleData }
  }, fishingTime)
}

// 重置捞瓶子状态
const resetFishing = () => {
  isFishing.value = false
  caughtBottle.value = null
}

// 回复瓶子
const replyToBottle = () => {
  console.log('回复瓶子:', caughtBottle.value)
  alert('回复功能开发中...')
}

// 点赞瓶子
const likeBottle = () => {
  if (caughtBottle.value) {
    caughtBottle.value.isLiked = !caughtBottle.value.isLiked
    caughtBottle.value.likes += caughtBottle.value.isLiked ? 1 : -1
  }
}
</script>

<style scoped>
.retrieve-bottle-page {
  padding: 20px;
  background: linear-gradient(135deg, #2ECC71 0%, #27AE60 25%, #16A085 50%, #1ABC9C 75%, #2ECC71 100%);
  min-height: 100vh;
  color: white;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

.page-header {
  text-align: center;
  margin-bottom: 30px;
}

.page-header h2 {
  font-size: 28px;
  margin-bottom: 10px;
  font-weight: 700;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.page-header p {
  font-size: 16px;
  opacity: 0.9;
}

.retrieve-content {
  max-width: 800px;
  margin: 0 auto;
}

.fishing-animation {
  padding: 40px 20px;
  text-align: center;
}

.fishing-rod {
  position: relative;
  width: 80px;
  height: 80px;
  margin: 0 auto 20px;
}

.rod-line {
  position: absolute;
  top: 10px;
  left: 50%;
  width: 2px;
  height: 60px;
  background: #8B4513;
  transform: translateX(-50%);
  animation: fishingLine 2s ease-in-out infinite;
}

.hook {
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 24px;
  animation: fishingHook 2s ease-in-out infinite;
}

@keyframes fishingLine {
  0%, 100% {
    height: 60px;
  }
  50% {
    height: 80px;
  }
}

@keyframes fishingHook {
  0%, 100% {
    transform: translateX(-50%) translateY(0px);
  }
  50% {
    transform: translateX(-50%) translateY(20px);
  }
}

.water-waves {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 20px 0;
}

.water-waves .wave {
  width: 20px;
  height: 20px;
  background: #3498DB;
  border-radius: 50%;
  animation: wave 1.5s ease-in-out infinite;
}

.water-waves .wave:nth-child(1) {
  animation-delay: 0s;
}

.water-waves .wave:nth-child(2) {
  animation-delay: 0.3s;
}

.water-waves .wave:nth-child(3) {
  animation-delay: 0.6s;
}

@keyframes wave {
  0%, 100% {
    transform: scale(1) translateY(0);
    opacity: 0.7;
  }
  50% {
    transform: scale(1.2) translateY(-10px);
    opacity: 1;
  }
}

.fishing-text {
  font-size: 18px;
  color: white;
  margin: 20px 0;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.caught-bottle {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  padding: 30px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
  animation: slideInUp 0.5s ease-out;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.bottle-animation {
  position: relative;
  margin: 20px 0;
}

.bottle-icon {
  font-size: 60px;
  animation: bounce 0.8s ease-in-out;
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-20px);
  }
  60% {
    transform: translateY(-10px);
  }
}

.sparkles {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.sparkle {
  position: absolute;
  font-size: 20px;
  animation: sparkle 2s ease-in-out infinite;
}

.sparkle:nth-child(1) {
  top: -40px;
  left: -30px;
  animation-delay: 0s;
}

.sparkle:nth-child(2) {
  top: -30px;
  right: -30px;
  animation-delay: 0.5s;
}

.sparkle:nth-child(3) {
  bottom: -40px;
  left: -20px;
  animation-delay: 1s;
}

@keyframes sparkle {
  0%, 100% {
    opacity: 0;
    transform: scale(0.5);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

.bottle-content-card {
  background: linear-gradient(135deg, #f0f9f4 0%, #e8f5e8 100%);
  border-radius: 12px;
  padding: 20px;
  margin: 20px 0;
  text-align: left;
}

.bottle-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.caught-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.caught-info h4 {
  margin: 0;
  font-size: 16px;
  color: #2c3e50;
}

.caught-distance {
  font-size: 12px;
  color: #6c757d;
}

.caught-message {
  font-size: 14px;
  color: #495057;
  line-height: 1.5;
  margin: 12px 0;
}

.caught-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.caught-tag {
  background: #E8F5E8;
  color: #2ECC71;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  border: 1px solid #D4F1D4;
}

.caught-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #6c757d;
}

.retrieve-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
  flex-wrap: wrap;
}

.action-btn {
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  backdrop-filter: blur(10px);
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

.reply-btn {
  background: #3498DB;
}

.reply-btn:hover {
  background: #2980B9;
}

.like-btn {
  background: #E74C3C;
}

.like-btn:hover {
  background: #C0392B;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.empty-state h3 {
  margin: 0 0 8px 0;
  font-size: 20px;
}

.empty-state p {
  margin: 0 0 24px 0;
  color: rgba(255, 255, 255, 0.7);
}

.primary-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 24px;
  padding: 12px 24px;
  color: white;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.primary-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .retrieve-bottle-page {
    padding: 16px;
  }

  .caught-bottle {
    padding: 20px;
  }

  .retrieve-actions {
    flex-direction: column;
    align-items: center;
  }

  .action-btn {
    width: 100%;
    max-width: 200px;
  }
}
</style>